<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
	String path= request.getContextPath();
	System.out.print(path);
	String basePath = request.getScheme() + "://"    + request.getServerName() + ":" + request.getServerPort()    + path + "/";
%>
<html>
<head>
<link rel="stylesheet" type="text/css" href="<%=path %>/pages/admin/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=path %>/pages/admin/easyui/themes/icon.css">
<script type="text/javascript" src="<%=path %>/pages/admin/easyui/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="<%=path %>/pages/admin/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<style>
textarea{font-size:12px;}
.clearfix{clear:both;}
#left{height:100%;float:left;}
#map{height:100%;width:65%;float:left;border-left:2px solid #bcbcbc;}
</style>
<script>
$(function(){
			$('#test').datagrid({
				title:'公司列表',
				iconCls:'',
				width:1024,
				height:600,
				nowrap: true,
				autoRowHeight: false,
				striped: true,
				sortName: 'code',
				sortOrder: 'desc',
				remoteSort: false,
				pagination:true,
				onClickRow:function(rowIndex, rowData){
					//alert(rowData.name);
					
					var datas = decodeURI("name="+rowData.name);
					$.ajax({
						type:"POST",
						url:'<%=path%>/pages/admin/Company!getComjson.do',
						data:datas,
						success:function(data){
							
							$("#e").window('open');
							//alert(data.post_long);
							//alert(1111);
							$("#e #name").val(data.name);
							$("#e #address").val(data.address);
							$("#e #law_person").val(data.law_person);
							$("#e #fund").val(data.registered_fund+"万元");
							$("#e #company_type").val(data.company_type);
							$("#e #business_type").val(data.business_type);
							$("#e #certificate").html(data.certificate);
							$("#e #location").val(data.post_long +","+ data.post_lat);
							//var j = eval("("+data+")");
							//alert(j.name)
							init();
						}
					});
				}
			});
			var p = $('#test').datagrid('getPager');
			
			$(p).pagination({
				onBeforeRefresh:function(){
					alert('before refresh');
				},
				total:'<s:property value="page.totalNum" />' ,
				pageSize:20
			});
			$("#btn").click(function(){
				$("#e #name").attr("readonly",false);
				$("#e #address").attr("readonly",false);
				$("#e #law_person").attr("readonly",false);
				$("#e #fund").attr("readonly",false);
				$("#e #company_type").attr("readonly",false);
				$("#e #business_type").attr("readonly",false);
			});
			$("#btns").click(function(){
				document.saveForm.submit();
				$('#test').datagrid('reload');
				alert("保存成功");
			});
		});
		
		
 
function qq(value,name){  
    //alert(value+":"+name);
   	$("#searchKey").val(value);
    $("#searchColumn").val(name);
   	document.searchForm.submit();
    //document.
}  

</script>
<style type="text/css">
body a{text-decoration: none;}
</style>
</head>
<body>
<div id="p" class="easyui-panel" title=""   
        style="width:500px;height:150px;padding:10px;margin-bottom:10px;background:#fafafa;"  
        data-options="iconCls:'icon-search',closable:true,  
                collapsible:true,minimizable:true,maximizable:true">
<a href="javascript:void(0)" id="sb" class="easyui-splitbutton"  
        data-options="menu:'#mm',iconCls:'icon-ok'" onclick="javascript:alert('ok')">Ok</a>  
<div id="mm" style="width:100px;">  
    <div data-options="iconCls:'icon-ok'"><s:a namespace="/pages/admin" action="%{actionName}" method="form">新建</s:a></div>  
    <div data-options="iconCls:'icon-cancel'">Cancel</div>  
</div>   
<s:form id="searchForm" name="searchForm" action="%{actionName}!search" namespace="/pages/admin" >
    <input id="ss" class="easyui-searchbox" style="width:300px"  
        data-options="searcher:qq,prompt:'Please Input Value',menu:'#mm'"></input>  
     <input id="searchKey" name="searchKey" type="hidden"/>     
     <input id="searchColumn" name="searchColumn" type="hidden"/>     
	<div id="mm" style="width:120px">  
	    <div data-options="name:'name',iconCls:'icon-ok'">名称</div>  
	    <div data-options="name:'address'">地址</div>
	    <div data-options="name:'company_type'">公司类型</div>  
	    <div data-options="name:'business_type'">行业类型</div>    
	</div>
</s:form>  
</div>

<table class="easyui-datagrid" id="test"> 
	<thead>  
	     <tr> 
	        <th data-options="field:'ck'"></th> 
	        <th data-options="field:'name'">名称</th>  
	        <th data-options="field:'fund'">注册资金</th>  
	        <th data-options="field:'address'">住所</th>  
	        <th data-options="field:'company_type'">企业类型</th>
	        <th data-options="field:'business_type'">行业类型</th>
	      </tr>  
	</thead>
	<tbody>
	<s:iterator value="page.list" status="rowstatus">
		<tr>
			<td><s:property
					value="#rowstatus.index+1+page.pageNum*page.pageSize" /></td>
			<td><s:property value="name" /></td>
			<td><s:property value="registered_fund" />万元</td>
			<td><s:property value="address" /></td>
			<td><s:property value="company_type" /></td>
			<td><s:property value="business_type" /></td>
			<td><s:a namespace="/pages/admin" method="form"
					action="%{actionName}">
					<s:param name="id" value="%{id}"></s:param>
			修改</s:a></td>
		</tr>
	</s:iterator>
	</tbody>
</table>
<div id="e" class="easyui-window" title="企业详情"   
        style="width:900px;height:450px;padding:10px;background:#fafafa;"  
        data-options="iconCls:'icon-save',closed:true,
                collapsible:true">
        <div id="left"> 
        <s:form id="saveForm" name="saveForm" action="Company!updateDes" namespace="/pages/admin">     	
        <p> 公司名称 ：<input id="name" name="name" type="text" size=25 readonly="readonly" /></p>
        
        <p>	法人代表  ：<input id="law_person" name="law_person" type="text" size=25 readonly="readonly"/></p>
        <p>	注册资金  ：<input id="fund" type="text" name="registered_fund" size=25 readonly="readonly"/></p>
    	<p>	公司类型  ：<input id="company_type" type="text" name="company_type" size=25 readonly="readonly"/></p>
    	<p>	住所  ：&nbsp;&nbsp;&nbsp;&nbsp;<input id="address" type="text" name="address" size=25 readonly="readonly"/></p>
    	<div><div style="float:left;">行业类型  ：</div><div style="float:left;"><textarea id="business_type" name="business_type" readonly="readonly"></textarea></div><div class="clearfix"></div></div>
    	<p> 法人代码  ：<span id="certificate"></span></p>
    	<p>坐标：<input id="location" name="location" type="text" size=20 readonly="readonly"/></p>
    	</s:form>
    	<div><a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">编辑</a>  
    		 <a id="btns" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'">保存</a>   
    		 <a id="btnqs" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'">重新定位</a>  
    		 </div>
    	</div>
    	
    	<div id="map" ></div>
</div>
</body>
</html>
<script type="text/javascript">
function init(){
var map = new BMap.Map("map");
var point = new BMap.Point(121.559243,29.825056);
map.centerAndZoom(point,12);
map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
map.enableScrollWheelZoom();    //启用滚轮放大缩小，默认禁用
//alert($("#e #location").val());
// 创建地址解析器实例
var lo = new Array();
lo = $("#e #location").val().split(",");
//alert(lo[0]);
//alert(lo[1]);
var marker = new BMap.Marker(new BMap.Point(lo[0],lo[1]));
map.addOverlay(marker);
var infoWindow = new BMap.InfoWindow('<strong>'+$("#e #name").val()+'</strong>');
marker.openInfoWindow(infoWindow);
function showInfo(e){
		alert(e.point.lng + ", " + e.point.lat);
		$("#e #location").val(e.point.lng + ", " + e.point.lat);
		var marker = new BMap.Marker(new BMap.Point(e.point.lng,e.point.lat));
		map.addOverlay(marker);
}
$("#btnqs").click(function(){
	map.clearOverlays();
	map.addEventListener("click", showInfo);
	
	});
}
</script>